#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

//修电脑后再下code测试git连接1

int flag;
uint64_t count = 0;

class my_zhishu
{

public:
    vector<int> get_zhishu(int target)
    {
        vector<int> p_arr(target + 1, 0); // 初始化最大下标为包含输入数字的数组
        int cs = 2, cs2 = 2;              // 定义与初始化
        p_arr[1] = 1;                     // 1不是质数

        while (cs < p_arr.size() / 2)
        {
            while (p_arr[cs] == 1)
            { // 如果当前数字非质数，则跳过(+1)
                cs++;
            }
            for (int i = 2; cs2 < p_arr.size(); i++)
            { // 为质数时,标记其之后的非质数
                cs2 = cs * i;
                if (cs2 < p_arr.size())
                {
                    p_arr[cs2] = 1;
                }
            }
            cs++;
            cs2 = cs; // 重置
        }
        vector<int> primes;
        for (int i = 2; i < p_arr.size(); i++)
        {
            if (p_arr[i] == 0)
            {
                primes.push_back(i);
            }
        }
        return primes;
    }
    vector<int> get_zhishu2(int target)
    {
        vector<int> p_arr(target + 1, 0); // 初始化最大下标为包含输入数字的数组
        int cs = 2, cs2 = 2;              // 定义与初始化
        p_arr[1] = 1;                     // 1不是质数

        while (cs < p_arr.size() / 2)
        {
            while (p_arr[cs] == 1)
            { // 如果当前数字非质数，则跳过(+1)
                cs++;
            }
            for (int i = 2; cs2 < p_arr.size(); i++)
            { // 为质数时,标记其之后的非质数
                cs2 = cs * i;
                if (cs2 < p_arr.size())
                {
                    p_arr[cs2] = 1;
                }
            }
            cs++;
            cs2 = cs; // 重置
        }
        return p_arr;
    }
};

class tools : public my_zhishu
{
public:
    void print(const vector<int> &n)
    {
        cout << "uint32_t" << "类型质数打印：" << endl;
        for (auto prime : n)
        {
            cout << prime << ",";
        }
        cout << endl;
    }

    uint32_t print(string n)
    {
        cout << n << endl;
        int num;
        cin >> num;
        return num;
    }

    int gdbh(int num, vector<int> n)
    {
        for (int i = 0; i < n.size(); i++)
        {
            for (int j = n.size() - 1; j >= 0; j--)
            {
                if (n[i] + n[j] == num)
                {
                    cout << n[i] << "+" << n[j] << "=" << num << endl;
                    return 0;
                }
                count++;
                // if (n[i] + n[j] < num){break;}
            }
        }
        // cout << num << "不能被两个质数加得" << endl;
        return 1;
    }

    int gdbh_q(int num, vector<int> n)
    {
        for (int i = 0; i < n.size(); i++)
        {
            for (int j = n.size() - 1; j >= 0; j--)
            {
                for (int k = 0; k < n.size(); k++)
                {
                    if (n[i] + n[j] + n[k] == num)
                    {
                        cout << n[i] << "+" << n[j] << "+" << n[k] << "=" << num << endl;
                        return 0;
                    }
                    if (n[i] + n[j] + n[k] > num)
                    {
                        break;
                    }
                    count++;
                }
            }
        }
        // cout << num << "不能被三个质数加得" << endl;
        flag = num;
        return 1;
    }
};

int main()
{

    // my_zhishu myzhishu_int;  // 定义实例用于处理int类型的质数
    cout << "开始" << endl;
    tools tools_; // 定义实例用于处理uint32_t类型的质数
    my_zhishu zs_list;

    int num = tools_.print("请输入一个大于等于4的数:");
    vector<int> arr = zs_list.get_zhishu(num);
    cout << "已得到质数数组" << endl;

    // tools_.print(arr); // 打印质数数组
    for (int i = 4; i <= num; i++)
    {
        if (tools_.gdbh(i, arr))
            tools_.gdbh_q(i, arr);
    }
    if (flag > 0)
    {
        cout << "存在不可被两个或三个质数加得的数" << flag << endl;
    }
    cout << "合数个数" << num - arr.size()-1<< endl;
    cout << "进行运算次数" << count << endl;

    return 0;
}